package drMadLap.android.talkyourday;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class IssueActivity extends Activity {
	
	ListView issueLstView;
	EditText issueEdit;
	Button btnAddIssue;
	Button btnRemoveIssue;
	
	TalkYourDayDBManager dbManager;
	List<IssueData> issueDatas;
	ArrayAdapter<String> lstAdapter;
	ArrayList<String> Issues;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
	    // TODO Auto-generated method stub
	    setContentView(R.layout.issueact);
	    issueEdit = (EditText)findViewById(R.id.editText_NewIssue);
	    
	    dbManager = new TalkYourDayDBManager(this);
	    
	    issueDatas = dbManager.GetIssueList();
	    
	    Issues = new ArrayList<String>();
	    for(IssueData dataItem : issueDatas)
	    {
	    	Issues.add(dataItem.Issue);
	    }
	    
	    lstAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, Issues);
	    issueLstView = (ListView)findViewById(R.id.listViewIssue);
	    issueLstView.setAdapter(lstAdapter);
	    issueLstView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
	    
	    btnAddIssue = (Button)findViewById(R.id.buttonAddIssue);
	    btnAddIssue.setOnClickListener(new OnClickListener()
	    {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				AddIssue();
			}
	    	
	    });
	    
	    btnRemoveIssue = (Button)findViewById(R.id.buttonRemoveIssue);
	    
	}
	
	private void AddIssue()
	{
		String newIssue = issueEdit.getText().toString();
		Issues.add(newIssue);
		dbManager.AddIssue(newIssue, false);
		
		lstAdapter.notifyDataSetChanged();
	}
	

}
